Skip to content

feat: Add instrumentation for tracking variables in debugging#4122

Merged
TomAFrench merged 21 commits intonoir-lang:masterfrom
manastech:debug-vars-instrumentation
Feb 5, 2024
Merged

feat: Add instrumentation for tracking variables in debugging#4122
TomAFrench merged 21 commits intonoir-lang:masterfrom
manastech:debug-vars-instrumentation

Conversation

@ggiraldez
Copy link
Copy Markdown
Contributor

Description

Problem*

Part of #3015

Summary*

This PR injects instrumentation snippets to the compiled code when running under a debugger to track the values assigned to variables in the program. It also provides the debugging context with necessary support code (in the form of foreign functions) and new functionality to inspect the tracked values.

Instrumentation occurs in two phases:

  1. During parsing, when assignments are detected, they are replaced by a small snippet that captures the value assigned and a temporary identifier for the variable being assigned, and a foreign function (oracle) is called with this information.
  2. At monomorphization time, ie. after the exact types of all variables has been determined, replacing the temporary identifier by a final one which will depend on the variable itself and the type at each instance of the function being compiled (for generic functions). Also, since structs are replaced for tuples during compilation, at this stage field and other member accesses is resolved for the final types (ie. indices in the tuples).

Additional Context

Besides the runtime support in the debugger, the compiler also injects a synthetic crate __debug which holds the definition of the oracle functions used in the injected code for tracking the variables and their assigned values.

These changes were extracted from the dap-with-vars branch of manastech/noir repository where most of the development of this feature occurred. We will submit additional PRs for the remaining features in that branch, notably improved REPL and DAP support to make use of this instrumentation code.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [Exceptional Case] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants